import React from "react";
import axios from "axios";
import {getUrlFor} from "@/services/UrlConfig";
import {formatResult} from "@/services/Utils";

const fetchAllStation = async (params: API.PageParams,
                        sort: Record<string, 'ascend'|'descend'|null> | null,
                        filter: Record<string, React.ReactText[]|null> | null) => {
  const reqParams = {
    start: params.current,
    size: params.pageSize
  }
  console.log(params, sort, filter);
  const res = await axios.get(getUrlFor("/station", reqParams));
  console.log(res.data);
  return formatResult(res);
}

const addStation = async (info: Domain.Station)=>{
  await axios.post(getUrlFor("/station"), info);
}

const rmStation = async (id: number|undefined) => {
  await axios.delete(getUrlFor("/station/"+id));
}

const updateStation = async (info: Domain.Station) => {
  await axios.put(getUrlFor("/station/"+info.id), info);
}

export {fetchAllStation, addStation, rmStation, updateStation}
